﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SO_DataFetcher.PubFunctions.Paraments;

namespace SO_DataFetcher.Forms
{
    public partial class FrmParament : Form
    {
        public string _paraId;
        private ParamentStruct _tempParament;
        private ParamentStruct _oldParament;
        private string _paraIndex;
        private string _operType;

        public FrmParament(string paraId,string type)
        {
            InitializeComponent();
            this._paraId = paraId;
            this._operType = type;
        }

        private void FrmParament_Load(object sender, EventArgs e)
        {
            Control control = new Control();

            if (PubParament.Paraments.ContainsKey(_paraId))
            {
                ParamentStruct parament = PubParament.Paraments[_paraId];
                _tempParament = parament;
                _oldParament = parament;

                this.Text = parament.Name;
                Label label = new Label();
                label.Text = parament.CtrLabel;

                switch (parament.CtrStyle)
                {
                    case "txtEdit":
                        control = new TextBox();
                        control.Text = parament.CtrValue;
                        control.TextChanged += new System.EventHandler(control_TextChanged); 
                        break;
                }

                this.panel1.Controls.Add(label);
                this.panel1.Controls.Add(control);
            }
        }

        private void control_TextChanged(object sender, EventArgs e)
        {
            Control control = (Control) sender;
            if (!string.IsNullOrEmpty(control.Text.Trim()))
            {
                _tempParament.CtrValue = control.Text.Trim();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {

            this.DialogResult = DialogResult.OK;
        }

    }
}
